package listeners;

import gui.MainWindow;
import gui.panel.ConnectionPanel;
import gui.panel.MainTabs;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

import Signals.Hello;

import network.NetworkInterface;


public class ConnectButtonListener implements ActionListener {

	private ConnectionPanel panel;
	private NetworkInterface networkInterface;
	
	public ConnectButtonListener(ConnectionPanel panel) {
		this.panel = panel;
	}
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		
		// instanciate the new network interface
		try {
			this.networkInterface = new NetworkInterface(this.panel.getTxtUsername().getText() + "@" + InetAddress.getLocalHost().getHostAddress(), 9876);
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		// switch panel
		MainWindow.getInstance().getContentPane().removeAll();
		MainWindow.getInstance().getContentPane().add(new MainTabs(this.networkInterface));
		MainWindow.getInstance().pack();
	}

}
